package org.robot.scm.pojos.config;

import java.util.Calendar;
import java.util.List;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.robot.scm.pojos.enums.PlatformEnum;

/**
 * @Author : Awn create on 2023/10/20 14:11
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class NightMode {

    /**
     * 包含的平台
     */
    private List<String> enables;

    /**
     * 模式时间区间
     */
    private List<Integer> modeTime;


    /**
     * 当前平台是否是勿扰模式
     */
    public boolean isInclude(BaseConfig config, PlatformEnum platformEnum) {
        NightMode nightMode = config.get().getNightMode();
        return nightMode.getEnables().contains(platformEnum.getVal());
    }

    /**
     * 判断当前时间是否处于夜晚模式定义时间区间内
     */
    public boolean isNight(BaseConfig config) {
        NightMode nightMode = config.get().getNightMode();
        Calendar calendar = Calendar.getInstance();
        int hour = calendar.get(Calendar.HOUR_OF_DAY);
        return hour >= nightMode.getModeTime().get(0) || hour < nightMode.getModeTime().get(1);
    }
}
